// 路由
let express = require('express')();
// 静态
let serve = require('express-static');

// 连接数据库

// 规划连接一个数据库
let mysql = require('mysql');
let sql = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '123456',
    database: 'sql'
});
// 尝试连接数据库
sql.connect();

express.get('/message', function(request, response) {
    sql.query(`SELECT * FROM news`, function(error, results) {
        if (error) {
            console.log(error)
        } else {
            response.send(results)
        }

    });
})
express.get('/con', function(request, response) {

    console.log(request.query.id)
    sql.query(`SELECT con,h3 FROM news WHERE id="${request.query.id}"`, function(error, results) {
        console.log(results)
        if (error) {
            console.log(error)
        } else {
            response.send(results[0])
        }

    });
})

express.use(serve(__dirname + '/static'))
express.listen(8080)